package pri.damai.xiaowu.auth.controller;

import org.springframework.validation.annotation.Validated;
import pri.damai.xiaowu.auth.model.Token;
import pri.damai.xiaowu.auth.service.SmsService;
import pri.damai.xiaowu.auth.service.TokenService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.*;
import pri.damai.xiaowu.common.core.vo.ResultVO;
import pri.damai.xiaowu.common.log.anno.XiaoWuLog;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 短信
 * @Desc
 * @Author DaMai
 * @Date 2021/10/19 13:44
 * 但行好事，莫问前程。
 */
@Api(tags = "登录前置接口")
@Validated
@XiaoWuLog
@RestController
@RequestMapping("/front")
public class LoginController {

    @Resource
    SmsService smsService;
    @Resource
    TokenService tokenService;

    @Operation(summary = "发送登录短信")
    @PostMapping("/sms/sendSms")
    public ResultVO<Void> sendSms(String phone) {
        smsService.sendSms(phone);
        return ResultVO.success();
    }

    @Operation(summary = "检查Token")
    @PostMapping("/checkToken")
    public ResultVO<Void> checkToken(@RequestBody @Valid Token token) {

        tokenService.checkToken(token.getToken());

        return ResultVO.success();
    }

}
